package compiler;

import java.util.Locale;

import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;

import compiler.dto.ErreurCompilation;
import compiler.dto.RapportCompilation;

public class Diagnostiquer implements DiagnosticListener<JavaFileObject>{
	
	RapportCompilation rapportCompilation;
	
	public Diagnostiquer(RapportCompilation rapportCompilation) {
		
		this.rapportCompilation = rapportCompilation;
		
	}
	
    public void report(Diagnostic<? extends JavaFileObject> diagnostic){
    	
    	ErreurCompilation erreurCompilation = new ErreurCompilation();
    	erreurCompilation.setType(diagnostic.getCode());
    	erreurCompilation.setMessage("line " + diagnostic.getLineNumber() + " : " + diagnostic.getMessage(Locale.ENGLISH) + " (" + diagnostic.getSource());
    	rapportCompilation.addErreurCompilation(erreurCompilation);
    	
        System.out.println("Line Number->" + diagnostic.getLineNumber());
        System.out.println("code->" + diagnostic.getCode());
        System.out.println("Message->" + diagnostic.getMessage(Locale.ENGLISH));
        System.out.println("Source->" + diagnostic.getSource());
    } 
}
